package com.absorbx.security;

import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
import org.springframework.security.GrantedAuthority;

@Node(jcrType = "ax:role")
public class Role implements GrantedAuthority {

	private static final long serialVersionUID = 795116239092882540L;

	@Field(jcrName = "ax:name")
	private String name;
	@Field(jcrName = "ax:description")
	private String description;
	@Field(path = true)
	private String path;
	@Field(uuid = true)
	private String uuid;

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public Role() {

	}

	public Role(final String name) {
		this.name = name;
	}

	public String getPath() {

		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getAuthority() {
		return getName();
	}

	public int compareTo(Object o) {
		return (equals(o) ? 0 : -1);
	}

	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (!(o instanceof Role)) {
			return false;
		}

		final Role role = (Role) o;

		return !(name != null ? !name.equals(role.name) : role.name != null);

	}

	@Override
	public String toString() {
		return "Role [description=" + description + ", name=" + name + "]";
	}

}
